﻿namespace Sidvall.IdentityManager.Security.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class AspNetRoles : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.IdentityManager.Data.IAspNetRoles
    {
        #region Public Members

        #region Id

        private string _Id;
        partial void OnBeforeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterIdPropertyChanged();
        public string Id
        { 
            get
            {
                return _Id;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Id = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Id);
                    OnBeforeIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Id", eventData.Value, true, true);
                        OnAfterIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Name

        private string _Name;
        partial void OnBeforeNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterNamePropertyChanged();
        public string Name
        { 
            get
            {
                return _Name;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Name = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Name);
                    OnBeforeNamePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Name", eventData.Value, true, true);
                        OnAfterNamePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public AspNetUsersCollectionItem AspNetUsers { get; set; }
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public AspNetRoles Copy()
        {
            return global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.Copy(this);
        }
        public AspNetRoles Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.IdentityManager.Data.IAspNetRoles item)
        {
            global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.Import(this, item);
        }
        public void Import(global::Sidvall.IdentityManager.Data.IAspNetRoles item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.Import(this, item, settings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<AspNetRoles> SaveItemAsync()
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.DataPortal.AspNetRolesManager.SaveItemAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AspNetRoles> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.DataPortal.AspNetRolesManager.SaveItemAsync(this, mode).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AspNetRoles> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.DataPortal.AspNetRolesManager.SaveItemAsync(this, settings).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AspNetRoles> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.DataPortal.AspNetRolesManager.SaveItemAsync(this, settings, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.Initialize(this, settings);
        }

        #endregion

        #region IAspNetRoles Members

        string global::Sidvall.IdentityManager.Data.IAspNetRoles.Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                this._Id = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IAspNetRoles.Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.IdentityManager.Data.IAspNetUsers> global::Sidvall.IdentityManager.Data.IAspNetRoles.AspNetUsers
        {
            get
            {
                if (this.AspNetUsers != null)
                    return this.AspNetUsers.Items;
                return null;
            }
        }
        void global::Sidvall.IdentityManager.Data.IAspNetRoles.SetAspNetUsers(Sidvall.Data.IDataRowProvider<global::Sidvall.IdentityManager.Data.IAspNetUsers> items)
        {
            this.AspNetUsers = (AspNetUsersCollectionItem)items;
        }

        #endregion

        #endregion
        #region Constructors

        public AspNetRoles()
        {
        }
        public AspNetRoles(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public AspNetRoles(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetRolesManager.Initialize(this);
        }

        #endregion
    }
}